<template>
    <div class="container-content">
        <el-form
            ref="formRef"
            :model="formObject"
            label-width="100px"
            label-position="left"
            :rules="rules"
        >
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-form-item
                        label="合同类型"
                        prop="contractSaleEntity.type"
                    >
                        <el-select
                            v-model="formObject.contractSaleEntity.type"
                            placeholder="请选择"
                            style="width: 100%"
                            @change="getContractType"
                        >
                            <el-option
                                v-for="item in typeOptions"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            >
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item
                        label="销售合同类型"
                        label-width="110px"
                        prop="contractSaleEntity.saleType"
                    >
                        <el-select
                            v-model="formObject.contractSaleEntity.saleType"
                            placeholder="请选择"
                            style="width: 100%"
                        >
                            <el-option
                                v-for="item in saleTypeOptions"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            >
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="合同模版">
                        <el-select
                            v-model="contractTemp"
                            placeholder="请选择"
                            style="width: 100%"
                            :disabled="
                                formObject.contractSaleEntity.type === ''
                                    ? true
                                    : false
                            "
                            @change="getContractContent"
                        >
                            <el-option
                                v-for="item in contractTypeOptions"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            >
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-card shadow="never">
                <el-row :gutter="20">
                    <el-col :span="8">
                        <el-form-item
                            label="合同名称"
                            prop="contractSaleEntity.contractName"
                        >
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity.contractName
                                "
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="合同金额">
                            <el-input
                                v-model="formObject.contractSaleEntity.money"
                                clearable
                                disabled
                            >
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="合同金额大写">
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity.moneyUpper
                                "
                                clearable
                                disabled
                            >
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="客户">
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity.customerName
                                "
                            >
                                <i
                                    slot="suffix"
                                    class="el-input__icon el-icon-notebook-2"
                                    style="cursor: pointer"
                                    @click="showDialog('customer')"
                                ></i>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="关联收款账户">
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity
                                        .collectingAccountId
                                "
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            label="法定/授权代表人"
                            label-width="120px"
                        >
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity.legalPerson
                                "
                            ></el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="销售组织">
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity.saleDeptName
                                "
                                disabled
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="8">
          <el-form-item label="乙方发货时间">
            <el-date-picker
              v-model="formObject.deliveryDay"
              type="date"
              placeholder="选择日期"
              style="width: 100%"
            >
            </el-date-picker>
          </el-form-item>
        </el-col> -->
                    <el-col :span="8">
                        <el-form-item label="发(提)货时间">
                            <el-date-picker
                                v-model="
                                    formObject.contractSaleEntity.deliveryTime
                                "
                                type="date"
                                placeholder="选择日期"
                                style="width: 100%"
                                format="yyyy-MM-dd"
                                value-format="yyyy-MM-dd"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="签约地点">
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity.signAddress
                                "
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="签订日期">
                            <el-date-picker
                                v-model="formObject.contractSaleEntity.signTime"
                                type="date"
                                placeholder="选择日期"
                                style="width: 100%"
                                format="yyyy-MM-dd"
                                value-format="yyyy-MM-dd"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="补充条款">
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity
                                        .supplementaryClauses
                                "
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="结算币别">
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity
                                        .settlementCurrencyName
                                "
                            >
                                <i
                                    slot="suffix"
                                    class="el-input__icon el-icon-notebook-2"
                                    style="cursor: pointer"
                                    @click="showDialog('currency')"
                                ></i>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="汇率">
                            <el-input
                                v-model="formObject.contractSaleEntity.rate"
                                clearable
                                disabled
                            >
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="交货方式">
                            <el-select
                                v-model="
                                    formObject.contractSaleEntity.deliveryType
                                "
                                placeholder="请选择"
                                style="width: 100%"
                            >
                                <el-option
                                    :key="1"
                                    label="由乙方包运，运费由乙方承担"
                                    :value="1"
                                >
                                </el-option>
                                <el-option
                                    :key="2"
                                    label="甲方自提货物，交货地点为乙方合肥仓库"
                                    :value="2"
                                >
                                </el-option>
                                <el-option
                                    :key="3"
                                    label="乙方代为联系物流，运费由甲方承担"
                                    :value="3"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            label="结算类型"
                            prop="contractSaleEntity.settlementMode"
                        >
                            <el-select
                                v-model="
                                    formObject.contractSaleEntity.settlementMode
                                "
                                placeholder="请选择"
                                style="width: 100%"
                            >
                                <el-option :key="1" label="款到发货" :value="1">
                                </el-option>
                                <el-option :key="2" label="货到付款" :value="2">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="结算方式">
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity
                                        .settlementTypeName
                                "
                                clearable
                            >
                                <i
                                    slot="suffix"
                                    class="el-input__icon el-icon-notebook-2"
                                    style="cursor: pointer"
                                    @click="showDialog('settlementType')"
                                ></i>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="票据类型">
                            <el-select
                                v-model="formObject.contractSaleEntity.billType"
                                placeholder="请选择"
                                style="width: 100%"
                            >
                                <el-option :key="1" label="专票" :value="1">
                                </el-option>
                                <el-option :key="2" label="普票" :value="2">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="保证金比例">
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity.bondRatio
                                "
                                clearable
                            >
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="价目表">
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity.priceListName
                                "
                                clearable
                            >
                                <i
                                    slot="suffix"
                                    class="el-input__icon el-icon-notebook-2"
                                    style="cursor: pointer"
                                    @click="showDialog('priceList')"
                                ></i>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="收款条件">
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity
                                        .receiptTermsName
                                "
                                clearable
                            >
                                <i
                                    slot="suffix"
                                    class="el-input__icon el-icon-notebook-2"
                                    style="cursor: pointer"
                                    @click="showDialog('receiptTerms')"
                                ></i>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            label="合同总金额本位币"
                            label-width="130px"
                        >
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity
                                        .totalAmountCurrency
                                "
                                clearable
                                disabled
                            >
                            </el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="保证金">
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity.bondAmount
                                "
                                clearable
                            >
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="本位币">
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity
                                        .standardCurrencyName
                                "
                                clearable
                                disabled
                            >
                                <i
                                    slot="suffix"
                                    class="el-input__icon el-icon-notebook-2"
                                    style="cursor: pointer"
                                    @click="showDialog('standardCurrency')"
                                ></i>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="汇率类型">
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity.rateTypeName
                                "
                                clearable
                            >
                                <i
                                    slot="suffix"
                                    class="el-input__icon el-icon-notebook-2"
                                    style="cursor: pointer"
                                    @click="showDialog('rateType')"
                                ></i>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="关联保证金">
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity.relationBond
                                "
                                clearable
                                disabled
                            >
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            label="关联保退款证金"
                            label-width="110px"
                        >
                            <el-input
                                v-model="
                                    formObject.contractSaleEntity
                                        .relationRefundBond
                                "
                                clearable
                                disabled
                            >
                            </el-input>
                        </el-form-item>
                    </el-col>
                   
                </el-row>
                <el-row :gutter="15">
                    <el-col :span="8">
                        <el-form-item label="是否含税">
                            <el-radio
                                border
                                :label="1"
                                v-model="
                                    formObject.contractSaleEntity.isIncludeTax
                                "
                                >是</el-radio
                            >
                            <el-radio
                                border
                                :label="2"
                                v-model="
                                    formObject.contractSaleEntity.isIncludeTax
                                "
                                >否</el-radio
                            >
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="是否价外税">
                            <el-radio
                                border
                                :label="1"
                                v-model="
                                    formObject.contractSaleEntity
                                        .isExtraPriceTax
                                "
                                >是</el-radio
                            >
                            <el-radio
                                border
                                :label="2"
                                v-model="
                                    formObject.contractSaleEntity
                                        .isExtraPriceTax
                                "
                                >否</el-radio
                            >
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item :label="change ? '变更原因' : '备注'">
                            <el-input
                                v-model="formObject.contractSaleEntity.remarks"
                                type="textarea"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

            </el-card>
            <Editor
                ref="editor"
                editor-id="editor"
                height="500px"
                :template-content="
                    formObject.contractSaleEntity.contractContent
                "
            />
            <!-- 物料列表 -->
            <template
                v-if="
                    formObject.contractSaleEntity.saleType !== 2 &&
                    formObject.contractSaleEntity.saleType !== 4
                "
            >
                <div class="desc-title">物料列表</div>
                <el-button
                    type="text"
                    size="medium"
                    @click="addNewRow('material')"
                >
                    新增行
                </el-button>
                <div class="floatright mb10">
                    <el-button type="primary" plain @click="showDialog('order')"
                        >选单</el-button
                    >

                    <el-button
                        type="primary"
                        plain
                        @click="showDialog('material', -1)"
                        >导入物料</el-button
                    >
                </div>
                <el-table
                    :data="formObject.materialDetailEntities"
                    style="width: 100%"
                    highlight-current-row
                    border
                    :summary-method="getSummaries"
                    show-summary
                >
                    <el-table-column label="操作" fixed>
                        <template slot-scope="scope">
                            <el-button
                                plain
                                icon="el-icon-minus"
                                size="mini"
                                @click="
                                    handleDataDelete(
                                        scope.$index,
                                        scope.row,
                                        'material'
                                    )
                                "
                            ></el-button>
                        </template>
                    </el-table-column>
                    <el-table-column
                        type="index"
                        label="序号"
                        width="50"
                        align="center"
                    ></el-table-column>
                    <el-table-column prop="materialCode" width="150">
                        <template slot="header">
                            物料编码<span class="required">*</span>
                        </template>
                        <template slot-scope="scope">
                            <el-form-item
                                label-width="0px"
                                style="margin: 0"
                                :rules="rules.materialCode"
                                :prop="
                                    'materialDetailEntities.' +
                                    scope.$index +
                                    '.materialCode'
                                "
                            >
                                <el-input
                                    v-model="scope.row.materialCode"
                                    clearable
                                    :disabled="change ? true : false"
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="
                                            showDialog('material', scope.$index)
                                        "
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="物料名称"
                        prop="materialName"
                        width="150"
                    >
                        <template slot-scope="scope">
                            <el-form-item
                                prop="materialName"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.materialName"
                                    disabled
                                    clearable
                                >
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>
                    <el-table-column label="规格型号" prop="model" width="150">
                        <template slot-scope="scope">
                            <el-form-item
                                prop="model"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.model"
                                    clearable
                                    disabled
                                >
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column prop="purchaseUnitName" width="150">
                        <template slot="header">
                            销售单位<span class="required">*</span>
                        </template>
                        <template slot-scope="scope">
                            <el-form-item
                                label-width="0px"
                                style="margin: 0"
                                :rules="rules.purchaseUnitName"
                                :prop="
                                    'materialDetailEntities.' +
                                    scope.$index +
                                    '.purchaseUnitName'
                                "
                            >
                                <el-input
                                    v-model="scope.row.purchaseUnitName"
                                    :disabled="change ? true : false"
                                    clearable
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="
                                            showDialog(
                                                'purchaseUnit',
                                                scope.$index
                                            )
                                        "
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>
                    <el-table-column label="销售数量" prop="number" width="150">
                        <template slot-scope="scope">
                            <el-form-item
                                prop="number"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.number"
                                    :disabled="change ? true : false"
                                    clearable
                                    @change="
                                        caculateNum(scope.row, scope.$index)
                                    "
                                >
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>
                    <el-table-column prop="pricingUnitName" width="150">
                        <template slot="header">
                            计价单位<span class="required">*</span>
                        </template>
                        <template slot-scope="scope">
                            <el-form-item
                                label-width="0px"
                                style="margin: 0"
                                :rules="rules.pricingUnitName"
                                :prop="
                                    'materialDetailEntities.' +
                                    scope.$index +
                                    '.pricingUnitName'
                                "
                            >
                                <el-input
                                    v-model="scope.row.pricingUnitName"
                                    :disabled="change ? true : false"
                                    clearable
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="
                                            showDialog(
                                                'pricingUnit',
                                                scope.$index
                                            )
                                        "
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="计价数量"
                        prop="pricingNum"
                        width="150"
                    >
                        <template slot-scope="scope">
                            <el-form-item
                                prop="pricingNum"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.pricingNum"
                                    disabled
                                    clearable
                                >
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>
                    <el-table-column label="单价" prop="price" width="150">
                        <template slot-scope="scope">
                            <el-form-item
                                prop="price"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.price"
                                    disabled
                                    clearable
                                >
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="库存数量"
                        prop="inventoryNum"
                        width="150"
                    >
                        <template slot-scope="scope">
                            <el-form-item
                                prop="inventoryNum"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.inventoryNum"
                                    disabled
                                    clearable
                                >
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="要货日期"
                        width="250"
                        prop="deliveryDate"
                    >
                        <template slot-scope="scope">
                            <el-form-item
                                prop="deliveryDate"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-date-picker
                                    v-model="scope.row.deliveryDate"
                                    type="date"
                                    placeholder="选择日期"
                                    style="width: 100%"
                                    format="yyyy-MM-dd"
                                    value-format="yyyy-MM-dd"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="含税单价"
                        prop="taxPrice"
                        width="150"
                    >
                        <template slot-scope="scope">
                            <el-form-item
                                prop="taxPrice"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.taxPrice"
                                    disabled
                                    clearable
                                >
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>
                    <!-- <el-table-column
                        label="折扣率%"
                        prop="discountRate"
                        width="150"
                    >
                        <template slot-scope="scope">
                            <el-form-item
                                prop="discountRate"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.discountRate"
                                    :disabled="change ? true : false"
                                    clearable
                                    @change="
                                        discountRateChange(
                                            scope.row,
                                            scope.$index
                                        )
                                    "
                                >
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column> -->

                    <el-table-column
                        label="金额"
                        prop="amountMoney"
                        width="150"
                    >
                        <template slot-scope="scope">
                            <el-form-item
                                prop="amountMoney"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.amountMoney"
                                    disabled
                                    clearable
                                >
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column label="税率%" prop="taxRate" width="150">
                        <template slot-scope="scope">
                            <el-form-item
                                prop="taxRate"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.taxRate"
                                    clearable
                                    :disabled="change ? true : false"
                                    @change="
                                        caculateNum(scope.row, scope.$index)
                                    "
                                >
                                    <i
                                        slot="suffix"
                                        class="el-input__icon el-icon-notebook-2"
                                        style="cursor: pointer"
                                        @click="
                                            showDialog('taxRate', scope.$index)
                                        "
                                    ></i>
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <!-- <el-table-column label="直接汇率">
                      <template slot-scope="scope">
                          <el-form-item
                              prop="directRate"
                              label-width="0px"
                              style="margin: 0"
                          >
                              <el-input
                                  v-model="scope.row.directRate"
                                  clearable
                                  :disabled="change ? true : false"
                                  @change="
                                      caculateNum(scope.row, scope.$index)
                                  "
                              >
                                  <i
                                      slot="suffix"
                                      class="el-input__icon el-icon-notebook-2"
                                      style="cursor: pointer"
                                      @click="
                                          showDialog('rate', scope.$index)
                                      "
                                  ></i>
                              </el-input>
                          </el-form-item>
                      </template>
                  </el-table-column>
                  <el-table-column label="间接汇率">
                      <template slot-scope="scope">
                          <el-form-item
                              prop="indirectRate"
                              label-width="0px"
                              style="margin: 0"
                          >
                              <el-input
                                  v-model="scope.row.indirectRate"
                                  clearable
                                  disabled
                              >
                              </el-input>
                          </el-form-item>
                      </template>
                  </el-table-column> -->
                    <el-table-column label="税额" prop="taxAmount" width="150">
                        <template slot-scope="scope">
                            <el-form-item
                                prop="taxAmount"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.taxAmount"
                                    clearable
                                    disabled
                                >
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="价税合计"
                        prop="totalTaxPrice"
                        width="150"
                    >
                        <template slot-scope="scope">
                            <el-form-item
                                prop="totalTaxPrice"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.totalTaxPrice"
                                    :disabled="change ? true : false"
                                    clearable
                                    @change="
                                        caculateNum(scope.row, scope.$index)
                                    "
                                >
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>
                    <!-- <el-table-column
                      label="需求组织"
                      prop="requireDeptName"
                      width="150"
                  >
                      <template slot-scope="scope">
                          <el-form-item
                              prop="requireDeptName"
                              label-width="0px"
                              style="margin: 0"
                          >
                              <el-input
                                  v-model="scope.row.requireDeptName"
                                  :disabled="change ? true : false"
                                  clearable
                              >
                              </el-input>
                          </el-form-item>
                      </template>
                  </el-table-column>
                  <el-table-column
                      label="收料组织"
                      prop="receivingDeptName"
                      width="150"
                  >
                      <template slot-scope="scope">
                          <el-form-item
                              prop="receivingDeptName"
                              label-width="0px"
                              style="margin: 0"
                          >
                              <el-input
                                  v-model="scope.row.receivingDeptName"
                                  :disabled="change ? true : false"
                                  clearable
                              >
                              </el-input>
                          </el-form-item>
                      </template>
                  </el-table-column> -->
                    <el-table-column prop="settlementDeptName" width="150">
                        <template slot="header">
                            结算组织<span class="required">*</span>
                        </template>
                        <template slot-scope="scope">
                            <el-form-item
                                label-width="0px"
                                style="margin: 0"
                                :rules="rules.settlementDeptName"
                                :prop="
                                    'materialDetailEntities.' +
                                    scope.$index +
                                    '.settlementDeptName'
                                "
                            >
                                <el-input
                                    v-model="scope.row.settlementDeptName"
                                    disabled
                                    clearable
                                >
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column label="备注" prop="ramarks" width="150">
                        <template slot-scope="scope">
                            <el-form-item
                                prop="ramarks"
                                label-width="0px"
                                style="margin: 0"
                            >
                                <el-input
                                    v-model="scope.row.ramarks"
                                    clearable
                                    :disabled="change ? true : false"
                                >
                                </el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>
                </el-table>
            </template>
            <!-- 弹窗 -->
            <el-dialog
                :title="dialogTitle"
                :visible.sync="open"
                append-to-body
                width="70%"
            >
                <!-- 订单列表 -->
                <el-table
                    v-if="dialogType === 'order'"
                    v-loading="loading"
                    ref="tableRef"
                    :data="tableData"
                    @selection-change="selectChangeItem"
                    border
                >
                    <el-table-column type="selection" width="55" align="center">
                    </el-table-column>
                    <el-table-column
                        type="index"
                        label="序号"
                        width="55"
                        align="center"
                    >
                    </el-table-column>
                    <el-table-column prop="materialCode" label="物料编码">
                        <template slot-scope="scope">
                            <span v-if="scope.row.materialCode">{{
                                scope.row.materialCode
                            }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="materialName" label="物料名称">
                        <template slot-scope="scope">
                            <span v-if="scope.row.materialName">{{
                                scope.row.materialName
                            }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="saleCode" label="销售编码">
                        <template slot-scope="scope">
                            <span v-if="scope.row.saleCode">{{
                                scope.row.saleCode
                            }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="kingDocCode" label="单据编码">
                        <template slot-scope="scope">
                            <span v-if="scope.row.kingDocCode">{{
                                scope.row.kingDocCode
                            }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="customerName" label="客户名称">
                        <template slot-scope="scope">
                            <span v-if="scope.row.customerName">{{
                                scope.row.customerName
                            }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="number" label="数量">
                        <template slot-scope="scope">
                            <span v-if="scope.row.number">{{
                                scope.row.number
                            }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="state" label="状态">
                        <template slot-scope="scope">
                            <span v-if="scope.row.state">{{
                                scope.row.state
                            }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 物料列表 -->
                <el-table
                    v-if="dialogType === 'material'"
                    v-loading="loading"
                    ref="tableRef"
                    :data="tableData"
                    @selection-change="selectChangeItem"
                    border
                >
                    <el-table-column type="selection" width="55" align="center">
                    </el-table-column>
                    <el-table-column
                        type="index"
                        label="序号"
                        width="55"
                        align="center"
                    >
                    </el-table-column>
                    <el-table-column prop="materialName" label="物料名称">
                        <template slot-scope="scope">
                            <span v-if="scope.row.materialName">{{
                                scope.row.materialName
                            }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="materialCode" label="物料编码">
                        <template slot-scope="scope">
                            <span v-if="scope.row.materialCode">{{
                                scope.row.materialCode
                            }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="typeName" label="分类名称">
                        <template slot-scope="scope">
                            <span v-if="scope.row.typeName">{{
                                scope.row.typeName
                            }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="unit" label="单位">
                        <template slot-scope="scope">
                            <span v-if="scope.row.unit">{{
                                scope.row.unit
                            }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="model" label="规格型号">
                        <template slot-scope="scope">
                            <span v-if="scope.row.model">{{
                                scope.row.model
                            }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="paramDesc" label="参数说明">
                        <template slot-scope="scope">
                            <span v-if="scope.row.paramDesc">{{
                                scope.row.paramDesc
                            }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="brand" label="品牌">
                        <template slot-scope="scope">
                            <span v-if="scope.row.brand">{{
                                scope.row.brand
                            }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="type" label="物料类型">
                        <template slot-scope="scope">
                            <span v-if="scope.row.type == '1'">自购物料</span>
                            <span v-if="scope.row.type == '2'">甲购物料</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 汇率 -->
                <el-table
                    border
                    v-loading="loading"
                    v-if="dialogType === 'rate'"
                    ref="tableRef"
                    :data="tableData"
                    @selection-change="selectChangeItem"
                >
                    <el-table-column type="selection" width="55" align="center">
                    </el-table-column>
                    <el-table-column
                        type="index"
                        label="序号"
                        width="55"
                        align="center"
                    ></el-table-column>
                    <el-table-column prop="sourceCurrency" label="原币别">
                        <template slot-scope="scope">{{
                            scope.row.sourceCurrency || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column prop="targetCurrency" label="目标币别">
                        <template slot-scope="scope">{{
                            scope.row.targetCurrency || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column prop="rateType" label="汇率类型">
                        <template slot-scope="scope">{{
                            scope.row.rateType || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column prop="directRate" label="直接汇率">
                        <template slot-scope="scope">{{
                            scope.row.directRate || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column prop="indirectRate" label="间接汇率">
                        <template slot-scope="scope">{{
                            scope.row.indirectRate || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column prop="isSend" label="是否推送金蝶">
                        <template slot-scope="scope">
                            <el-tag v-if="scope.row.isSend == 1" type="success"
                                >是</el-tag
                            >
                            <el-tag
                                v-else-if="scope.row.isSend == 2"
                                type="danger"
                                >否</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="updateTime" label="更新日期">
                        <template slot-scope="scope">{{
                            scope.row.updateTime || "--"
                        }}</template>
                    </el-table-column>
                </el-table>
                <!-- 税率 -->
                <el-table
                    border
                    v-loading="loading"
                    v-if="dialogType === 'taxRate'"
                    ref="tableRef"
                    :data="tableData"
                    @selection-change="selectChangeItem"
                >
                    <el-table-column
                        type="selection"
                        width="55"
                        align="center"
                    ></el-table-column>
                    <el-table-column
                        type="index"
                        label="序号"
                        align="center"
                    ></el-table-column>
                    <el-table-column prop="rateCode" label="编码">
                        <template slot-scope="scope">{{
                            scope.row.rateCode || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column prop="title" label="名称"
                        ><template slot-scope="scope">{{
                            scope.row.title || "--"
                        }}</template></el-table-column
                    >
                    <el-table-column prop="deptId" label="所属公司"
                        ><template slot-scope="scope">{{
                            scope.row.deptId || "--"
                        }}</template></el-table-column
                    >
                    <el-table-column prop="rate" label="税率"
                        ><template slot-scope="scope">{{
                            scope.row.rate || "--"
                        }}</template></el-table-column
                    >
                    <el-table-column prop="dataStatus" label="数据状态">
                        <template slot-scope="scope">
                            <el-tag v-if="scope.row.dataStatus === 1"
                                >创建</el-tag
                            >
                            <el-tag v-else-if="scope.row.dataStatus === 2"
                                >审核中</el-tag
                            >
                            <el-tag v-else-if="scope.row.dataStatus === 3"
                                >已审核</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="isAddTax" label="是否增值税">
                        <template slot-scope="scope">
                            <el-tag
                                v-if="scope.row.isAddTax === 1"
                                type="success"
                                >是</el-tag
                            >
                            <el-tag
                                v-else-if="scope.row.isAddTax === 2"
                                type="danger"
                                >否</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="isBuyReplace" label="买方代扣代缴">
                        <template slot-scope="scope">
                            <el-tag
                                v-if="scope.row.isBuyReplace === 1"
                                type="success"
                                >是</el-tag
                            >
                            <el-tag
                                v-else-if="scope.row.isBuyReplace === 2"
                                type="danger"
                                >否</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="isSellReplace" label="卖方代扣代缴">
                        <template slot-scope="scope">
                            <el-tag
                                v-if="scope.row.isSellReplace === 1"
                                type="success"
                                >是</el-tag
                            >
                            <el-tag
                                v-else-if="scope.row.isSellReplace === 2"
                                type="danger"
                                >否</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="isTaxInvoice"
                        label="是否开增值税发票"
                    >
                        <template slot-scope="scope">
                            <el-tag
                                v-if="scope.row.isTaxInvoice === 1"
                                type="success"
                                >是</el-tag
                            >
                            <el-tag
                                v-else-if="scope.row.isTaxInvoice === 2"
                                type="danger"
                                >否</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="effectiveTime" label="生效日期"
                        ><template slot-scope="scope">{{
                            scope.row.effectiveTime || "--"
                        }}</template></el-table-column
                    >
                    <el-table-column prop="invalidTime" label="失效日期"
                        ><template slot-scope="scope">{{
                            scope.row.invalidTime || "--"
                        }}</template></el-table-column
                    >
                </el-table>
                <!-- 币别-->
                <el-table
                    border
                    v-loading="loading"
                    v-if="dialogType === 'currency'"
                    ref="tableRef"
                    :data="tableData"
                    @selection-change="selectChangeItem"
                >
                    <el-table-column
                        type="selection"
                        width="55"
                        align="center"
                    ></el-table-column>
                    <el-table-column
                        type="index"
                        width="55"
                        align="center"
                        label="序号"
                    ></el-table-column>
                    <el-table-column prop="currencyName" label="币别名称">
                        <template slot-scope="scope">{{
                            scope.row.currencyName || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column prop="currencySymbol" label="货币代码">
                        <template slot-scope="scope">{{
                            scope.row.currencySymbol || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column prop="code" label="币别编码">
                        <template slot-scope="scope">{{
                            scope.row.code || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column prop="amountAccuracy" label="金额精度">
                        <template slot-scope="scope">{{
                            scope.row.amountAccuracy || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column prop="dataStatus" label="数据状态">
                        <template slot-scope="scope">
                            <el-tag v-if="scope.row.dataStatus === 1"
                                >创建</el-tag
                            >
                            <el-tag v-else-if="scope.row.dataStatus === 2"
                                >审核中</el-tag
                            >
                            <el-tag v-else-if="scope.row.dataStatus === 3"
                                >已审核</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="isDisabled" label="是否禁用">
                        <template slot-scope="scope">
                            <el-tag
                                v-if="scope.row.isDisabled === 1"
                                type="danger"
                                >是</el-tag
                            >
                            <el-tag
                                v-else-if="scope.row.isDisabled === 2"
                                type="success"
                                >否</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="priceAccuracy" label="单价精度">
                        <template slot-scope="scope">{{
                            scope.row.priceAccuracy || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column prop="showFlag" label="单据显示货币符号">
                        <template slot-scope="scope">
                            <el-tag
                                v-if="scope.row.showFlag === 1"
                                type="success"
                                >是</el-tag
                            >
                            <el-tag
                                v-else-if="scope.row.showFlag === 2"
                                type="danger"
                                >否</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 汇率类型 -->
                <el-table
                    border
                    v-loading="loading"
                    v-if="dialogType === 'rateType'"
                    ref="tableRef"
                    :data="tableData"
                    @selection-change="selectChangeItem"
                >
                    <el-table-column
                        type="selection"
                        width="55"
                        align="center"
                    ></el-table-column>
                    <el-table-column
                        type="index"
                        label="序号"
                        width="55"
                        align="center"
                    ></el-table-column>
                    <el-table-column prop="code" label="编码">
                        <template slot-scope="scope">
                            <span>{{ scope.row.code || "--" }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="name" label="名称">
                        <template slot-scope="scope">
                            <span>{{ scope.row.name || "--" }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="directRateAccuracy"
                        label="直接汇率精度"
                    >
                        <template slot-scope="scope">
                            <span>{{
                                scope.row.directRateAccuracy || "--"
                            }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="indirectRateAccuracy"
                        label="间接汇率精度"
                    >
                        <template slot-scope="scope">
                            <span>{{
                                scope.row.indirectRateAccuracy || "--"
                            }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="isSystem" label="是否系统预设">
                        <template slot-scope="scope">
                            <el-tag v-if="scope.row.isSystem">是</el-tag>
                            <el-tag v-else-if="!scope.row.isSystem">否</el-tag>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="userId" label="录入人">
                        <template slot-scope="scope">
                            <span>{{ scope.row.userId || "--" }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="changeId" label="修改人">
                        <template slot-scope="scope">
                            <span>{{ scope.row.changeId || "--" }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="describe" label="描述">
                        <template slot-scope="scope">
                            <span>{{ scope.row.describe || "--" }}</span>
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 销售价目表 -->
                <el-table
                    border
                    v-loading="loading"
                    v-if="dialogType === 'priceList'"
                    ref="tableRef"
                    :data="tableData"
                    @selection-change="selectChangeItem"
                >
                    <el-table-column
                        type="selection"
                        width="55"
                        align="center"
                    ></el-table-column>
                    <el-table-column
                        type="index"
                        label="序号"
                        width="55"
                        align="center"
                    ></el-table-column>
                    <el-table-column prop="markedPriceName" label="价目名称">
                        <template slot-scope="scope">
                            <span>{{ scope.row.markedPriceName || "--" }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="materialCode" label="物料编码">
                        <template slot-scope="scope">
                            <span>{{ scope.row.materialCode || "--" }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="materialName" label="物料名称">
                        <template slot-scope="scope">
                            <span>{{ scope.row.materialName || "--" }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="priceObject" label="价目对象">
                        <template slot-scope="scope">
                            <span>{{ scope.row.priceObject || "--" }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="priceType" label="价目类型">
                        <template slot-scope="scope">
                            <span>{{ scope.row.priceType || "--" }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="startPrice" label="至价格">
                        <template slot-scope="scope">
                            <span>{{ scope.row.startPrice || "--" }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="endPrice" label="价格">
                        <template slot-scope="scope">
                            <span>{{ scope.row.endPrice || "--" }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="currencyName" label="币别">
                        <template slot-scope="scope">
                            <span>{{ scope.row.currencyName || "--" }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="state" label="状态">
                        <template slot-scope="scope">
                            <span>{{ scope.row.state || "--" }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="includingTax" label="是否含税">
                        <template slot-scope="scope">
                            <el-tag
                                type="danger"
                                v-if="scope.row.includingTax == '0'"
                                >否</el-tag
                            >
                            <el-tag
                                type="success"
                                v-else-if="scope.row.includingTax == '1'"
                                >是</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 收款条件 -->
                <el-table
                    border
                    v-loading="loading"
                    v-if="dialogType === 'receiptTerms'"
                    ref="tableRef"
                    :data="tableData"
                    @selection-change="selectChangeItem"
                >
                    <el-table-column
                        type="selection"
                        width="55"
                        align="center"
                    ></el-table-column>
                    <el-table-column
                        type="index"
                        label="序号"
                        width="55"
                        align="center"
                    ></el-table-column>
                    <el-table-column prop="conditionCode" label="编码">
                        <template slot-scope="scope">
                            {{ scope.row.conditionCode || "--" }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="title" label="名称">
                        <template slot-scope="scope">
                            {{ scope.row.title || "--" }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="deptId" label="所属公司">
                        <template slot-scope="scope">
                            {{ scope.row.deptId || "--" }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="type" label="类型">
                        <template slot-scope="scope">
                            <el-tag v-if="scope.row.type === 1"
                                >收款条件</el-tag
                            >
                            <el-tag v-else-if="scope.row.type === 2"
                                >付款条件</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="dueSetStandard"
                        label="到期日设置标准"
                    >
                        <template slot-scope="scope">
                            <span v-if="scope.row.dueSetStandard === 1"
                                >按比例</span
                            >
                            <span v-else-if="scope.row.dueSetStandard === 2"
                                >按金额</span
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="dueTime" label="到期日计算日期">
                        <template slot-scope="scope">
                            <span v-if="scope.row.dueSetStandard === 1"
                                >订单日期</span
                            >
                            <span v-else-if="scope.row.dueSetStandard === 2"
                                >应收单业务日期</span
                            >
                            <span v-else-if="scope.row.dueSetStandard === 3"
                                >出库日期</span
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="receiptType" label="收款方式">
                        <template slot-scope="scope">
                            <span v-if="scope.row.dueSetStandard === 1"
                                >按到期日收款</span
                            >
                            <span v-else-if="scope.row.dueSetStandard === 2"
                                >按订单收款</span
                            >
                            <span v-else-if="scope.row.dueSetStandard === 3"
                                >按物料明细收款</span
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="conditionDesc" label="描述">
                        <template slot-scope="scope">
                            {{ scope.row.conditionDesc || "--" }}
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 客户 -->
                <el-table
                    border
                    v-loading="loading"
                    v-if="dialogType === 'customer'"
                    ref="tableRef"
                    :data="tableData"
                    @selection-change="selectChangeItem"
                >
                    <el-table-column type="selection" width="55" align="center">
                    </el-table-column>
                    <el-table-column
                        type="index"
                        label="序号"
                        width="55"
                        align="center"
                    />
                    <el-table-column prop="customerName" label="客户名称">
                        <template slot-scope="scope">
                            {{ scope.row.customerName || "--" }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="telPhone" label="电话">
                        <template slot-scope="scope">
                            {{ scope.row.telPhone || "--" }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="createTime" label="创建时间">
                        <template slot-scope="scope">
                            {{ scope.row.createTime || "--" }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="state" label="状态">
                        <template slot-scope="scope">
                            <el-tag
                                type="success"
                                v-if="scope.row.state === '0'"
                                >正常</el-tag
                            >
                            <el-tag
                                type="danger"
                                v-else-if="scope.row.state === '1'"
                                >异常</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 单位 -->
                <el-table
                    border
                    v-loading="loading"
                    v-if="
                        dialogType === 'pricingUnit' ||
                        dialogType === 'purchaseUnit'
                    "
                    ref="tableRef"
                    :data="tableData"
                    @selection-change="selectChangeItem"
                >
                    <el-table-column type="selection" width="55" align="center">
                    </el-table-column>
                    <el-table-column
                        type="index"
                        width="55"
                        label="序号"
                        align="center"
                    />
                    <el-table-column
                        prop="meteringUnitCode"
                        label="计量单位编码"
                    >
                        <template slot-scope="scope">{{
                            scope.row.meteringUnitCode || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column
                        prop="meteringUnitName"
                        label="计量单位名称"
                    >
                        <template slot-scope="scope">{{
                            scope.row.meteringUnitName || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column prop="roundingType" label="舍入类型">
                        <template slot-scope="scope">{{
                            scope.row.roundingType || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column
                        prop="meteringUnitDescribe"
                        label="计量单位描述"
                    >
                        <template slot-scope="scope">{{
                            scope.row.meteringUnitDescribe || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column prop="defaultDegree" label="精度">
                        <template slot-scope="scope">{{
                            scope.row.defaultDegree || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column
                        prop="exchangeDenominator"
                        label="换算分母"
                    >
                        <template slot-scope="scope">{{
                            scope.row.exchangeDenominator || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column prop="exchangeNumerator" label="换算分字">
                        <template slot-scope="scope">{{
                            scope.row.exchangeNumerator || "--"
                        }}</template>
                    </el-table-column>
                    <el-table-column prop="exchangeType" label="换算类型">
                        <template slot-scope="scope">{{
                            scope.row.exchangeType || "--"
                        }}</template>
                    </el-table-column>
                </el-table>
                <!-- 结算方式 -->
                <el-table
                    border
                    v-loading="loading"
                    v-if="dialogType === 'settlementType'"
                    ref="tableRef"
                    :data="tableData"
                    @selection-change="selectChangeItem"
                >
                    <el-table-column
                        type="selection"
                        width="55"
                        align="center"
                    ></el-table-column>
                    <el-table-column
                        type="index"
                        label="序号"
                        width="55"
                        align="center"
                    ></el-table-column>
                    <el-table-column prop="bizCode" label="编码">
                        <template slot-scope="scope">
                            {{ scope.row.bizCode || "--" }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="title" label="名称">
                        <template slot-scope="scope">
                            {{ scope.row.title || "--" }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="isDefault"
                        label="是否为默认结算方式"
                    >
                        <template slot-scope="scope">
                            <el-tag
                                v-if="scope.row.isDefault === 1"
                                type="success"
                                >是</el-tag
                            >
                            <el-tag
                                v-else-if="scope.row.isDefault === 2"
                                type="danger"
                                >否</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="isDisabled" label="是否禁用">
                        <template slot-scope="scope">
                            <el-tag
                                v-if="scope.row.isDisabled === 1"
                                type="danger"
                                >是</el-tag
                            >
                            <el-tag
                                v-else-if="scope.row.isDisabled === 2"
                                type="success"
                                >否</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="isSupportLinePay"
                        label="是否支持网银付款"
                    >
                        <template slot-scope="scope">
                            <el-tag
                                v-if="scope.row.isSupportLinePay === 1"
                                type="success"
                                >是</el-tag
                            >
                            <el-tag
                                v-else-if="scope.row.isSupportLinePay === 2"
                                type="danger"
                                >否</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="isPayFee" label="是否支付手续费">
                        <template slot-scope="scope">
                            <el-tag
                                v-if="scope.row.isPayFee === 1"
                                type="success"
                                >是</el-tag
                            >
                            <el-tag
                                v-else-if="scope.row.isPayFee === 2"
                                type="danger"
                                >否</el-tag
                            >
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                    class="pagination mt10"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="page"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="limit"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total"
                    background
                >
                </el-pagination>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="cancelSelect">取 消</el-button>
                    <el-button type="primary" @click="confirmSelect"
                        >确 定</el-button
                    >
                </span>
            </el-dialog>
        </el-form>
    </div>
</template>
<script>
import {
    getList,
    addSaleContract,
    editSaleList,
    getDetailSale,
} from "@/api/system/contract";
import {
    getOrderList,
    getContractMaterialLists,
    getMaterialList,
    getSaleContractMaterialLists,
    getOrderDetail,
} from "@/api/system/purchase";
import { getCompute } from "@/api/finance/info";
import { getSaleList, getSaleDetail, getPriceList } from "@/api/system/sale";
import {
    getExchangeData,
    getTaxData,
    getCurrencyData,
    getSettleData,
    getPayData,
    getExchangeTypeData,
    getCustomerList,
    getUnitData,
} from "@/api/base/data";
import { getInfo } from "@/api/login";
import { getMaterial } from "@/api/bim/bim";
import { convertToRMB } from "@/utils/utils";
import Editor from "./editor/index.vue";
import customerId from "@/components/dialog/customer";
export default {
    components: {
        Editor,
        customerId,
    },
    props: { id: String, change: Boolean },
    data() {
        return {
            contractType: "",
            contractTemp: "",
            contractTypeOptions: [],
            dialogTitle: "",
            dialogType: "",
            loading: false,
            open: false,
            total: 0,
            limit: 10,
            page: 1,
            currentIndex: "",
            selectItem: [],
            tableData: [],
            settlementTypeOptions: [],

            formObject: {
                contractSaleEntity: {
                    billType: 1,
                    businessType: "",
                    changeTime: "",
                    collectingAccountId: "",
                    contractContent: "",

                    contractName: "",
                    contractNumber: "",
                    contractTempId: "",
                    contractTempName: "",

                    settlementCurrencyId: "",
                    settlementCurrencyName: "",
                    settlementCurrencyCode: "",
                    standardCurrency: "",
                    standardCurrencyName: "",
                    standardCurrencyCode: "",
                    bondRatio: "",
                    isIncludeTax: 1,
                    isExtraPriceTax: 1,
                    priceListId: "",
                    priceListCode: "",
                    priceListName: "",
                    receiptTermsId: "",
                    receiptTermsName: "",
                    totalAmountCurrency: "",
                    bondAmount: "",
                    rateType: "",
                    rateTypeName: "",
                    relationBond: "",
                    relationRefundBond: "",

                    createTime: "",
                    customerId: "",
                    customerName: "",
                    deliveryDay: "",
                    deliveryTime: this.parseTime(new Date()),
                    deliveryType: "",
                    deptId: "",
                    id: "",
                    instanceId: "",
                    isChange: 0,
                    isClose: 0,

                    legalPerson: "",
                    limit: 0,
                    materialCode: "",
                    materialName: "",
                    modelId: "",
                    money: "",
                    moneyUpper: "",
                    page: 0,
                    parentId: "",
                    saleDeptId: "",
                    saleDeptName: "",
                    payDay: 0,
                    saleType: "",
                    settlementMode: 1,
                    settlementType: "",
                    settlementTypeName: "",
                    signAddress: "",
                    signTime: this.parseTime(new Date()),
                    state: "",
                    supplementaryClauses: "",
                    taxRate: "",
                    rate: "",

                    token: "",
                    type: "",
                    businessType: "9",
                    modelId: this.$store.state.workflow.businessConfig.id,
                },
                materialDetailEntities: [],
                saleOrderEntities: [],
            },
            rules: {
                materialCode: [
                    {
                        required: true,
                        message: "请输入物料编码",
                        trigger: "blur",
                    },
                ],
                purchaseUnitName: [
                    {
                        required: true,
                        message: "请输入销售单位",
                        trigger: "blur",
                    },
                ],
                pricingUnitName: [
                    {
                        required: true,
                        message: "请输入计价单位",
                        trigger: "blur",
                    },
                ],
                settlementDeptName: [
                    {
                        required: true,
                        message: "请输入结算组织",
                        trigger: "blur",
                    },
                ],
                inventoryUnit: [
                    {
                        required: true,
                        message: "请输入库存单位",
                        trigger: "blur",
                    },
                ],
                contractSaleEntity: {
                    type: [
                        {
                            required: true,
                            message: "请选择合同类型",
                            trigger: "blur",
                        },
                    ],
                    saleType: [
                        {
                            required: true,
                            message: "请选择销售合同类型",
                            trigger: "blur",
                        },
                    ],
                    contractName: [
                        {
                            required: true,
                            message: "请选择合同名称",
                            trigger: "blur",
                        },
                    ],
                },
            },
            typeOptions: [
                { label: "光伏材料销售合同", value: 176 },
                { label: "逆变器销售合同", value: 177 },
                { label: "组件销售合同", value: 178 },
            ],
            saleTypeOptions: [
                { label: "普通合同", value: 1 },
                { label: "金额合同", value: 2 },
                { label: "物料分组合同", value: 3 },
                { label: "框架合同", value: 4 },
            ],
        };
    },
    methods: {
        //分页器size
        handleSizeChange(val) {
            this.limit = val;
            const nameMap = {
                order: () => {
                    this.getOrderLists();
                },
                material: () => {
                    this.getMaterialLists();
                },
                rate: () => {
                    this.getRateList();
                },
                taxRate: () => {
                    this.getTaxRateList();
                },
                currency: () => {
                    this.getCurrencyList();
                },
                rateType: () => {
                    this.getRateTypeList();
                },
                priceList: () => {
                    this.getPriceLists();
                },
                receiptTerms: () => {
                    this.receiptTermsList();
                },
                customer: () => {
                    this.getCustomerList();
                },
                pricingUnit: () => {
                    this.getUnit();
                },
                purchaseUnit: () => {
                    this.getUnit();
                },
                settlementType: () => {
                    this.settlementTypeList();
                },
            };
            nameMap[this.dialogType] ? nameMap[this.dialogType]() : "";
        },
        //分页器当前页
        handleCurrentChange(val) {
            this.page = val;
            const nameMap = {
                order: () => {
                    this.getOrderLists();
                },
                material: () => {
                    this.getMaterialLists();
                },
                rate: () => {
                    this.getRateList();
                },
                taxRate: () => {
                    this.getTaxRateList();
                },
                currency: () => {
                    this.getCurrencyList();
                },
                rateType: () => {
                    this.getRateTypeList();
                },
                priceList: () => {
                    this.getPriceLists();
                },
                receiptTerms: () => {
                    this.receiptTermsList();
                },
                customer: () => {
                    this.getCustomerList();
                },
                pricingUnit: () => {
                    this.getUnit();
                },
                purchaseUnit: () => {
                    this.getUnit();
                },
                settlementType: () => {
                    this.settlementTypeList();
                },
            };
            nameMap[this.dialogType] ? nameMap[this.dialogType]() : "";
        },
        getContractType(val) {
            getList({
                typeId: val,
            }).then((res) => {
                if (res.code === 200) {
                    this.contractTypeOptions = res.rows.map((item) => {
                        return {
                            id: item.id,
                            value: item.id,
                            label: item.tempName,
                            content: item.contractTempContent,
                        };
                    });
                }
            });
        },
        getContractContent(val) {
            this.formObject.contractSaleEntity.contractContent =
                this.contractTypeOptions.find((item) => item.id == val).content;
        },
        // 获取详情回显
        getDetailData(id) {
            getDetailSale(id).then((res) => {
                this.formObject = res.data;
                this.getContractType(res.data.type);
            });
        },
        submit(cb) {
            this.$refs["formRef"].validate((valid) => {
                if (!valid) {
                    this.$message.error("请完整填写信息！");
                    return;
                }
                if (this.id) {
                    if (this.change) {
                        // 变更合同
                        this.$set(
                            this.formObject.contractSaleEntity,
                            "parentId",
                            this.id
                        );
                        addSaleContract(this.formObject).then((res) => {
                            if (res.code === 200) {
                                this.$message({
                                    message: "变更成功！",
                                    type: "success",
                                });
                            }
                        });
                    } else {
                        // 修改
                        editSaleList(this.formObject).then((res) => {
                            if (res.code === 200) {
                                this.$message({
                                    message: "修改成功！",
                                    type: "success",
                                });
                                this.id = "";
                                resetValue(this.formObject);
                            }
                        });
                    }
                } else {
                    // 新增
                    addSaleContract(this.formObject).then((res) => {
                        if (res.code === 200) {
                            this.$message({
                                message: "新增成功！",
                                type: "success",
                            });
                            this.$store.commit(
                                "workflow/SET_BUSINESSDRAWER",
                                false
                            );
                        }
                    });
                }
            });
        },
        // 新增物料列表
        handleDataAdd_material() {
            if (this.formObject.materialDetailEntities == undefined) {
                this.formObject.materialDetailEntities = [];
            }
            let materialObj = this.getMaterialObj();
            this.formObject.materialDetailEntities.push(materialObj);
        },
        // 删除订单列表
        handleDataDelete(index, row) {
            this.$confirm("请确认是否要删除此行?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    this.formObject.materialDetailEntities.splice(index, 1);
                    this.$message({
                        type: "success",
                        message: "删除成功!",
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除",
                    });
                });
        },
        addNewRow() {
            this.handleDataAdd_material();
        },
        // 获取订单
        getOrderLists() {
            this.dialogTitle = "选择订单物料";
            let limit = 10;
            let page = 1;
            getSaleList({ limit, page }).then((res) => {
                if (res.code === 200) {
                    this.loading = false;
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                }
            });
        },
        // 获取汇率
        getRateList(index) {
            this.dialogTitle = "选择汇率";
            index >= 0 ? (this.currentIndex = index) : "";
            getExchangeData().then((res) => {
                this.tableData = res.rows;
                this.total = res.total;
                this.loading = false;
            });
        },
        // 弹窗勾选item
        selectChangeItem(val) {
            this.selectItem = val;
        },
        // 弹出弹窗
        showDialog(type, index) {
            this.open = true;
            this.loading = true;
            this.dialogType = type;
            const nameMap = {
                order: () => {
                    this.getOrderLists();
                },
                material: () => {
                    this.getMaterialLists(index);
                },
                rate: () => {
                    this.getRateList(index);
                },
                taxRate: () => {
                    this.getTaxRateList(index);
                },
                currency: () => {
                    this.getCurrencyList();
                },
                rateType: () => {
                    this.getRateTypeList();
                },
                priceList: () => {
                    this.getPriceLists();
                },
                receiptTerms: () => {
                    this.receiptTermsList();
                },
                customer: () => {
                    this.getCustomerList();
                },
                pricingUnit: () => {
                    this.getUnit(index);
                },
                purchaseUnit: () => {
                    this.getUnit(index);
                },
                settlementType: () => {
                    this.settlementTypeList();
                },
            };
            nameMap[this.dialogType] ? nameMap[this.dialogType]() : "";
        },

        // 弹框取消按钮
        cancelSelect() {
            this.open = false;
            this.selectItem = [];
        },
        // 弹框确认按钮
        confirmSelect() {
            const nameMap = {
                order: () => {
                    this.handleOrder();
                },
                material: () => {
                    this.handleMaterial();
                },
                rate: () => {
                    if (this.selectItem.length !== 1) {
                        this.$message.error("请选择一条记录！");
                        return;
                    }
                    this.formObject.materialDetailEntities[
                        this.currentIndex
                    ].directRate = this.selectItem[0].directRate;
                    this.formObject.materialDetailEntities[
                        this.currentIndex
                    ].indirectRate = this.selectItem[0].indirectRate;
                    this.open = false;
                },
                taxRate: () => {
                    if (this.selectItem.length !== 1) {
                        this.$message.error("请选择一条记录！");
                        return;
                    }

                    this.$set(
                        this.formObject.materialDetailEntities[
                            this.currentIndex
                        ],
                        "taxRate",
                        this.selectItem[0].rate
                    );
                    this.caculateNum(
                        this.formObject.materialDetailEntities[
                            this.currentIndex
                        ],
                        this.currentIndex
                    );
                    this.open = false;
                },

                currency: () => {
                    if (this.selectItem.length !== 1) {
                        this.$message.error("请选择一条记录！");
                        return;
                    }
                    this.formObject.contractSaleEntity.settlementCurrencyName =
                        this.selectItem[0].currencyName;
                    this.formObject.contractSaleEntity.settlementCurrencyId =
                        this.selectItem[0].id;
                    this.formObject.contractSaleEntity.settlementCurrencyCode =
                        this.selectItem[0].code;
                    this.formObject.contractSaleEntity.rate =
                        this.selectItem[0].rate;
                    if (this.formObject.contractSaleEntity.rate) {
                        this.changeRate();
                    }
                    this.open = false;
                },
                priceList: () => {
                    if (this.selectItem.length !== 1) {
                        this.$message.error("请选择一条记录！");
                        return;
                    }
                    this.formObject.contractSaleEntity.priceListId =
                        this.selectItem[0].id;
                    this.formObject.contractSaleEntity.priceListName =
                        this.selectItem[0].markedPriceName;
                    this.formObject.contractSaleEntity.priceListCode =
                        this.selectItem[0].priceCode;
                    this.open = false;
                },
                receiptTerms: () => {
                    if (this.selectItem.length !== 1) {
                        this.$message.error("请选择一条记录！");
                        return;
                    }
                    this.formObject.contractSaleEntity.receiptTermsId =
                        this.selectItem[0].id;
                    this.formObject.contractSaleEntity.receiptTermsName =
                        this.selectItem[0].title;
                    this.open = false;
                },
                customer: () => {
                    if (this.selectItem.length !== 1) {
                        this.$message.error("请选择一条记录！");
                        return;
                    }
                    this.formObject.contractSaleEntity.customerId =
                        this.selectItem[0].id;
                    this.formObject.contractSaleEntity.customerName =
                        this.selectItem[0].customerName;
                    this.open = false;
                },
                pricingUnit: () => {
                    if (this.selectItem.length !== 1) {
                        this.$message.error("请选择一条记录！");
                        return;
                    }
                    // 计价单位
                    this.formObject.materialDetailEntities[
                        this.currentIndex
                    ].pricingUnit = this.selectItem[0].id;
                    this.formObject.materialDetailEntities[
                        this.currentIndex
                    ].pricingUnitName = this.selectItem[0].meteringUnitName;

                    this.open = false;
                },
                purchaseUnit: () => {
                    if (this.selectItem.length !== 1) {
                        this.$message.error("请选择一条记录！");
                        return;
                    }
                    // 销售单位
                    this.formObject.materialDetailEntities[
                        this.currentIndex
                    ].purchaseUnit = this.selectItem[0].id;
                    this.formObject.materialDetailEntities[
                        this.currentIndex
                    ].purchaseUnitName = this.selectItem[0].meteringUnitName;
                    // 计价单位
                    this.formObject.materialDetailEntities[
                        this.currentIndex
                    ].pricingUnit = this.selectItem[0].id;
                    this.formObject.materialDetailEntities[
                        this.currentIndex
                    ].pricingUnitName = this.selectItem[0].meteringUnitName;
                    this.open = false;
                },
                settlementType: () => {
                    if (this.selectItem.length !== 1) {
                        this.$message.error("请选择一条记录！");
                        return;
                    }
                    this.formObject.contractSaleEntity.settlementTypeName =
                        this.selectItem[0].title;
                    this.formObject.contractSaleEntity.settlementType =
                        this.selectItem[0].bizCode;
                    this.open = false;
                },
            };
            nameMap[this.dialogType] ? nameMap[this.dialogType]() : "";
        },
        // 选单回显
        handleOrder() {
            if (this.selectItem.length === 0) {
                this.$message.error("请选择一条记录！");
                return;
            }
            if (this.selectItem.length >= 1) {
                let flag = this.selectItem.every((item) => {
                    return item.supplierId === this.selectItem[0].supplierId;
                });
                if (!flag) {
                    this.$message.error("请选择相同供应商的订单！");
                    return;
                }
                this.selectItem.forEach((item) => {
                    let materialObj = this.getMaterialObj();
                    Object.keys(item).forEach((itemKey) => {
                        Object.keys(materialObj).forEach((materialKey) => {
                            if (itemKey === materialKey) {
                                materialObj[materialKey] = item[itemKey];
                            }

                            if (itemKey === "materialDetailId") {
                                materialObj["sourceMaterialDetailId"] =
                                    item["materialDetailId"];
                            }
                            if (itemKey === "saleOrderId") {
                                materialObj["sourceRelationId"] =
                                    item["saleOrderId"];
                            }
                            if (materialKey === "id") {
                                materialObj["id"] = "";
                            }
                        });
                    });

                    this.formObject.materialDetailEntities.push(materialObj);
                });
                getSaleDetail(this.selectItem[0].saleOrderId).then((res) => {
                    // res.data.supplierName
                    //     ? (this.formObject.contractSaleEntity.supplierName =
                    //           res.data.supplierName)
                    //     : "";
                    // res.data.supplierId
                    //     ? (this.formObject.contractSaleEntity.supplierId =
                    //           res.data.supplierId)
                    //     : "";
                    console.log("res", res.data);
                });
                this.open = false;
            }
        },
        // 物料回显
        handleMaterial() {
            // console.log("this.currentIndex", this.currentIndex);

            if (this.currentIndex < 0) {
                // 导入物料按钮
                this.selectItem.forEach((item) => {
                    let materialObj = this.getMaterialObj();
                    Object.keys(item).forEach((itemKey) => {
                        Object.keys(materialObj).forEach((materialKey) => {
                            if (itemKey === materialKey) {
                                materialObj[materialKey] = item[itemKey];
                            }
                            if (itemKey === "pricingUnitName") {
                                materialObj["inventoryUnitName"] =
                                    item[itemKey];
                            }
                            if (itemKey === "pricingUnit") {
                                materialObj["inventoryUnit"] = item[itemKey];
                            }
                        });
                    });
                    this.formObject.materialDetailEntities.push(materialObj);
                });
            }
            if (this.currentIndex >= 0) {
                // 图标按钮
                if (this.selectItem.length !== 1) {
                    this.$message.error("请选择一条记录！");
                    return;
                }
                this.selectItem.forEach((item) => {
                    let materialObj = this.getMaterialObj();
                    Object.keys(item).forEach((itemKey) => {
                        Object.keys(materialObj).forEach((materialKey) => {
                            if (itemKey === materialKey) {
                                materialObj[materialKey] = item[itemKey];
                            }
                            if (itemKey === "id") {
                                materialObj["id"] = "";
                            }
                            if (itemKey === "pricingUnitName") {
                                materialObj["inventoryUnitName"] =
                                    item[itemKey];
                            }
                            if (itemKey === "pricingUnit") {
                                materialObj["inventoryUnit"] = item[itemKey];
                            }
                        });
                    });
                    this.$set(
                        this.formObject.materialDetailEntities,
                        this.currentIndex,
                        materialObj
                    );
                });
            }
            this.open = false;
        },
        // 获取结算方式
        settlementTypeList() {
            this.dialogTitle = "选择结算方式";
            this.loading = true;
            let params = {
                page: this.page,
                limit: this.limit,
            };
            getSettleData(params).then((res) => {
                this.tableData = res.rows;
                this.total = res.total;
                this.loading = false;
            });
        },
        // 获取单位
        getUnit(index) {
            this.dialogTitle = "选择单位";
            this.loading = true;
            index >= 0 ? (this.currentIndex = index) : "";
            let params = {
                page: this.page,
                limit: this.limit,
            };
            getUnitData(params).then((res) => {
                this.tableData = res.rows;
                this.total = res.total;
                this.loading = false;
            });
        },
        // 获取客户
        getCustomerList() {
            this.dialogTitle = "选择客户";
            this.loading = true;
            let params = {
                page: this.page,
                limit: this.limit,
            };
            getCustomerList(params).then((res) => {
                this.tableData = res.rows;
                this.total = res.total;
                this.loading = false;
            });
        },
        // 获取收款条件
        receiptTermsList() {
            this.dialogTitle = "选择收款条件";
            this.loading = true;
            let params = {
                page: this.page,
                limit: this.limit,
                type: 1,
            };
            getPayData(params).then((res) => {
                this.tableData = res.rows;
                this.total = res.total;
                this.loading = false;
            });
        },
        // 获取价目表
        getPriceLists() {
            this.dialogTitle = "选择销售价目表";
            this.loading = true;
            let params = {
                page: this.page,
                limit: this.limit,
            };
            getPriceList(params).then((res) => {
                this.tableData = res.data.records;
                this.total = res.data.total;
                this.loading = false;
            });
        },
        // 获取汇率类型
        getRateTypeList() {
            this.dialogTitle = "选择汇率类型";
            this.loading = true;
            let params = {
                page: this.page,
                limit: this.limit,
            };
            getExchangeTypeData(params).then((res) => {
                this.tableData = res.rows;
                this.total = res.total;
                this.loading = false;
            });
        },
        // 获取物料
        getMaterialLists(index) {
            this.dialogTitle = "选择物料";

            this.currentIndex = index;
            this.loading = true;
            // getMaterialList().then((res) => {
            //     if (res.code === 200) {
            //         this.loading = false;
            //         this.tableData = res.data.records;
            //         this.total = res.data.total;
            //     }
            // });
            let params = {
                page: this.page,
                limit: this.limit,
            };
            getMaterial(params).then((res) => {
                if (res.code === 200) {
                    this.loading = false;
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                }
            });
        },
        // 税率
        getTaxRateList(index) {
            this.dialogTitle = "选择税率";
            index >= 0 ? (this.currentIndex = index) : "";
            this.loading = true;
            let params = {
                page: this.page,
                limit: this.limit,
            };
            getTaxData(params).then((res) => {
                this.loading = false;
                this.tableData = res.rows;
                this.total = res.total;
            });
        },
        // 币别
        getCurrencyList() {
            this.dialogTitle = "选择币别";
            let params = {
                page: this.page,
                limit: this.limit,
            };
            getCurrencyData(params).then((res) => {
                this.tableData = res.rows;
                this.total = res.total;
                this.loading = false;
            });
        },
        // 计算值
        caculateNum(row, index) {
            // 数量，税率，价税合计，汇率
            if (row == undefined) {
                return;
            }
            if (row.number >= 0) {
                // 计价数量
                this.$set(
                    this.formObject.materialDetailEntities[index],
                    "pricingNum",
                    row.number
                );
                //   库存数量
                this.$set(
                    this.formObject.materialDetailEntities[index],
                    "inventoryNum",
                    row.number
                );
            }
            if (row.totalTaxPrice) {
                // 合同总金额本位币=主表上总价税合计*汇率
                const total = this.formObject.materialDetailEntities.reduce(
                    (sum, item) => sum + Number(item.totalTaxPrice),
                    0
                );
                this.formObject.contractSaleEntity.totalAmountCurrency =
                    total * this.formObject.contractSaleEntity.rate;
                // 合同金额 = 价税合计之和
                this.formObject.contractSaleEntity.money = total;
                this.formObject.contractSaleEntity.moneyUpper = convertToRMB(total);
            }
            
            if (
                row.number &&
                row.taxRate &&
                row.totalTaxPrice &&
                this.formObject.contractSaleEntity.rate
            ) {
                let totalTaxAmount = row.totalTaxPrice;
                let number = row.number;
                let taxRate = row.taxRate;
                let rate = this.formObject.contractSaleEntity.rate;
                getCompute({ number, taxRate, totalTaxAmount, rate }).then(
                    (res) => {
                        // 单价
                        this.$set(
                            this.formObject.materialDetailEntities[index],
                            "price",
                            res.data.price
                        );
                        // 金额
                        this.$set(
                            this.formObject.materialDetailEntities[index],
                            "amountMoney",
                            res.data.amount
                        );
                        // 税额
                        this.$set(
                            this.formObject.materialDetailEntities[index],
                            "taxAmount",
                            res.data.taxAmount
                        );
                        // 含税单价
                        this.$set(
                            this.formObject.materialDetailEntities[index],
                            "taxPrice",
                            res.data.taxUnitPrice
                        );
                    }
                );
            }
        },
        // 汇率
        changeRate() {
            this.formObject.materialDetailEntities.forEach((item, index) => {
                if (
                    item.number &&
                    item.taxRate &&
                    item.totalTaxPrice &&
                    this.formObject.contractSaleEntity.rate
                ) {
                    let totalTaxAmount = item.totalTaxPrice;
                    let number = item.number;
                    let taxRate = item.taxRate;
                    let rate = this.formObject.contractSaleEntity.rate;
                    getCompute({
                        number,
                        taxRate,
                        totalTaxAmount,
                        rate,
                    }).then((res) => {
                        this.$set(
                            this.formObject.materialDetailEntities[index],
                            "price",
                            res.data.price
                        );
                        this.$set(
                            this.formObject.materialDetailEntities[index],
                            "amountMoney",
                            res.data.amount
                        );

                        this.$set(
                            this.formObject.materialDetailEntities[index],
                            "taxAmount",
                            res.data.taxAmount
                        );

                        this.$set(
                            this.formObject.materialDetailEntities[index],
                            "taxPrice",
                            res.data.taxUnitPrice
                        );
                    });
                }
            });
        },
        // // 折扣率
        // discountRateChange(row, index) {
        //     // 金额=原来金额-(原来金额*折扣率)
        //     this.formObject.materialDetailEntities[index].amountMoney =
        //         this.formObject.materialDetailEntities[index].amountMoney -
        //         this.formObject.materialDetailEntities[index].amountMoney *
        //             this.formObject.materialDetailEntities[index].discountRate;
        //     // 税额=原来税额-(原来税额*折扣率)
        //     this.formObject.materialDetailEntities[index].taxAmount =
        //         this.formObject.materialDetailEntities[index].taxAmount -
        //         this.formObject.materialDetailEntities[index].taxAmount *
        //             this.formObject.materialDetailEntities[index].discountRate;
        //     // 价税合计=原价税合计-(原价税合计*折扣率)
        //     this.formObject.materialDetailEntities[index].totalTaxPrice =
        //         this.formObject.materialDetailEntities[index].totalTaxPrice -
        //         this.formObject.materialDetailEntities[index].totalTaxPrice *
        //             this.formObject.materialDetailEntities[index].discountRate;
        // },
        getMaterialObj() {
            let obj = {
                amountMoney: "",
                batchNum: "",
                businessTaxCostPrice: "",
                changeTime: "",
                changeType: "",
                containsTaxPrice: "",
                createTime: "",
                deliveryAddress: "",
                deliveryDate: this.parseTime(new Date()),
                deliveryLocation: "",
                discountAmount: "",
                discountRate: "",
                executeStatus: "",
                id: "",
                sourceMaterialDetailId: "",
                inventoryId: "",
                inventoryNum: 0,
                inventoryUnit: "",
                isGiveaway: true,

                limit: 0,
                model: "",
                material: {
                    allowAsset: "",
                    allowInventory: "",
                    allowOutsource: "",
                    allowProduce: "",
                    allowPurchase: "",
                    allowSale: "",
                    barCode: "",
                    brand: "",
                    businessType: "",
                    configurationProduction: "",
                    costPriceRatio: "",
                    createBy: "",
                    createTime: "",
                    dataState: "",
                    defaultTaxRate: "",
                    deptId: "",
                    disableBy: "",
                    examineBy: "",
                    examineTime: "",
                    grossWeight: "",
                    heightStr: "",
                    id: "",
                    imgUrl: "",
                    instanceId: "",
                    inventoryType: "",
                    isChange: "",

                    kit: "",
                    lengthStr: "",

                    materialCode: "",
                    materialDesc: "",
                    materialGroup: "",
                    materialInventoryEntity: {
                        batchInfo: "",
                        batchRule: "",
                        checkCycle: "",
                        convertDirection: "",
                        costUnit: "",
                        createBy: "",
                        createTime: "",
                        currency: "",
                        day: "",
                        economicOrderingBatch: "",
                        id: "",
                        inventoryUnit: "",
                        isBatch: "",
                        isCheck: "",
                        isLock: "",
                        isMaxInventory: "",
                        isMinInventory: "",
                        isOrderGoods: "",
                        isSafeInventory: "",
                        isTrueCheck: "",
                        materialId: "",
                        maxInventoyNum: "",
                        minInventoryNum: "",
                        orderGoodsNum: "",
                        pageNo: 0,
                        pageSize: 0,
                        params: {},
                        qualityManage: "",
                        qualityNum: "",
                        qualityUnit: "",
                        referenceCost: "",
                        remark: "",
                        safeInventoryNum: "",
                        searchValue: "",
                        serviceLife: "",
                        standardNumber: "",
                        supportUnit: "",
                        updateBy: "",
                        updateTime: "",
                        warePosition: "",
                        warehouseCode: "",
                    },
                    materialName: "",
                    materialPlanAttributeEntity: {
                        createBy: "",
                        createTime: "",
                        fAllowPartDelay: "",
                        fBaseVarLeadTimeLotSize: "",
                        fBaseVarLeadTimeLotSizeUnit: "",
                        fCanDelayDays: 0,
                        fCanLeadDays: 0,
                        fCheckLeadTime: 0,
                        fCheckLeadTimeType: "",
                        fDelayExtendDay: 0,
                        fFixLeadTime: 0,
                        fFixLeadTimeType: "",
                        fIncreaseQty: 0,
                        fIncreaseQtyUnit: "",
                        fIsMrpComBill: "",
                        fIsMrpComReq: "",
                        fLeadExtendDay: 0,
                        fMaxPoqty: 0,
                        fMfgPolicyId: "",
                        fMinPoqty: 0,
                        fMinPoqtyUnit: "",
                        fOrderIntervalTime: 0,
                        fOrderIntervalTimeType: "",
                        fOrderPolicy: "",
                        fPlanBatchSplitQty: "",
                        fPlanBatchSplitQtyUnit: "",
                        fPlanGroupId: "",
                        fPlanIdent: "",
                        fPlanIntervalsDays: 0,
                        fPlanOffsetTime: 0,
                        fPlanOffsetTimeType: "",
                        fPlanSafeStockQty: 0,
                        fPlanSafeStockQtyUnit: "",
                        fPlanTimeZone: 0,
                        fPlanWorkshop: "",
                        fPlanerId: "",
                        fPlanningStrategy: "",
                        fProScheTrackId: "",
                        fProductLine: "",
                        fRequestTimeZone: 0,
                        fSupplySourceId: "",
                        fVarLeadTime: 0,
                        fVarLeadTimeLotSize: "",
                        fVarLeadTimeLotSizeUnit: "",
                        fVarLeadTimeType: "",
                        fWriteOffQty: "",
                        fWriteOffQtyUnit: "",
                        id: "",
                        materialId: "",
                        maxPoqtyUnit: "",
                        pageNo: 0,
                        pageSize: 0,
                        params: {},
                        remark: "",
                        searchValue: "",
                        updateBy: "",
                        updateTime: "",
                    },
                    materialProcureEntity: {
                        agentProcure: "",
                        barCodeRule: "",
                        createBy: "",
                        createTime: "",
                        dayProduction: 0,
                        dayProductionUnit: "",
                        defaultSupplier: "",
                        defunctProductionLine: "",
                        expenseItem: "",
                        id: "",
                        isControl: "",
                        isDayProduction: "",
                        isMaterialReturn: "",
                        isQuota: "",
                        isReq: "",
                        materialId: "",
                        minPackNum: "",
                        minSpiltNum: 0,
                        outsourcePricingUnit: "",
                        outsourceType: "",
                        outsourceUnit: "",
                        pageNo: 0,
                        pageSize: 0,
                        params: {},
                        procureGroup: "",
                        procureId: "",
                        procurePricingUnit: "",
                        procureType: "",
                        procureUnit: "",
                        quotaMode: "",
                        remark: "",
                        repeatPutNum: "",
                        searchValue: "",
                        takeOverDelay: 0,
                        takeOverDown: "",
                        takeOverLead: 0,
                        takeOverUp: "",
                        updateBy: "",
                        updateTime: "",
                    },
                    materialProductEntity: {
                        createBy: "",
                        createTime: "",
                        deptId: "",
                        fBackFlushType: "",
                        fConsumVolatility: "",
                        fDefaultLineId: "",
                        fDefaultRouting: "",
                        fFinishReceiptOverRate: "",
                        fFinishReceiptShortRate: "",
                        fIsCompleteSet: "",
                        fIsEnableSchedule: "",
                        fIsKitting: "",
                        fIsMainPrd: "",
                        fIsMinissueQty: "",
                        fIsProductLine: "",
                        fIsSNCarryToParent: "",
                        fIssueType: "",
                        fMdlId: "",
                        fMdlMaterialId: "",
                        fMinissueQty: 0,
                        fMinissueUnitId: "",
                        fOrgTrustBillType: "",
                        fOverControlMode: "",
                        fPerUnitStandHour: "",
                        fPickBinId: "",
                        fPickStockId: "",
                        fProduceBillType: "",
                        fProduceUnitId: "",
                        fStandHourUnitId: "",
                        fStdLaborPrePareTime: "",
                        fStdLaborProcessTime: "",
                        fStdMachinePrepareTime: "",
                        fStdMachineProcessTime: "",
                        fWorkShopId: "",
                        fbkfltime: "",
                        fbomunitid: "",
                        ffixloss: "",
                        fisecn: "",
                        flosspercent: "",
                        id: "",
                        materialId: "",
                        pageNo: 0,
                        pageSize: 0,
                        params: {},
                        remark: "",
                        searchValue: "",
                        updateBy: "",
                        updateTime: "",
                    },
                    materialProperty: "",
                    materialQualityEntity: {
                        createBy: "",
                        createTime: "",
                        fCheckDelivery: "",
                        fCheckEntrusted: "",
                        fCheckIncoming: "",
                        fCheckOther: "",
                        fCheckProduct: "",
                        fCheckReturn: "",
                        fCheckStock: "",
                        fCheckSubFtnMtrl: "",
                        fEWLeadDay: "",
                        fEnableCyclistQCSTK: "",
                        fEnableCyclistQcstkew: "",
                        fFirstQCControlType: "",
                        fIncQcSchemeId: "",
                        fIncSampSchemeId: "",
                        fInspectGroupId: "",
                        fInspectorId: "",
                        fIsFirstInspect: "",
                        fStockCycle: "",
                        id: "",
                        materialId: "",
                        pageNo: 0,
                        pageSize: 0,
                        params: {},
                        remark: "",
                        searchValue: "",
                        updateBy: "",
                        updateTime: "",
                    },
                    materialSaleEntity: {
                        allowReleaseOrder: "",
                        allowReturns: "",
                        atpCheck: "",
                        controlSurpassUnit: "",
                        createBy: "",
                        createTime: "",
                        dropOutCount: "",
                        fisReturnPart: "",
                        fisaftersale: "",
                        fisproductfiles: "",
                        fiswarranted: "",
                        fwarranty: "",
                        fwarrantyunitid: "",
                        id: "",
                        isFavourableTax: "",
                        materialId: "",
                        pageNo: 0,
                        pageSize: 0,
                        params: {},
                        remark: "",
                        saleDownPrice: "",
                        saleGroup: "",
                        saleOutbound: "",
                        salePricingUnit: "",
                        saleUnit: "",
                        searchValue: "",
                        startOrderNum: 0,
                        surpassDown: "",
                        surpassUp: "",
                        taxType: "",
                        taxTypeCode: "",
                        updateBy: "",
                        updateTime: "",
                    },
                    mnemonicCode: "",
                    model: "",
                    modelId: "",
                    netWeight: "",
                    oldMaterialCode: "",
                    pageNo: 0,
                    pageSize: 0,
                    params: {},
                    reasonForDisable: "",
                    remark: "",
                    searchValue: "",
                    sizeUnit: "",
                    state: "",
                    subItems: "",
                    taxType: "",
                    typeName: "",
                    unit: "",
                    updateBy: "",
                    updateTime: "",
                    volume: "",
                    weightUnit: "",
                    wideStr: "",
                },
                materialCode: "",
                materialName: "",
                materialId: "",
                netAmount: "",
                noTaxMoney: "",
                number: 0,
                orderDelivery: {
                    batchNum: "",
                    bomVer: "",
                    changeTime: "",
                    controlDeliveryNum: true,
                    controlDeliveryTime: true,
                    createTime: "",
                    deliveryDelayDay: "",
                    deliveryDown: "",
                    deliveryEarlyTime: "",
                    deliveryLatestTime: "",
                    deliveryLeadDay: "",
                    deliveryUp: "",
                    id: "",

                    materialId: "",
                    materialName: "",
                    orderDeliveryDetails: [
                        {
                            address: "",
                            changeTime: "",
                            confirmComment: "",
                            confirmNum: "",
                            confirmTime: "",
                            createTime: "",
                            deliveredNum: "",
                            deliveryTime: "",
                            id: "",

                            location: "",
                            num: "",
                            orderDeliveryId: "",
                            orderId: "",
                            planUnit: "",
                            surplusNum: "",
                            userId: "",
                        },
                    ],
                    orderId: "",
                    receiveDept: "",
                    receiveOrg: "",
                    requireDept: "",
                    requireOrg: "",
                    supplierBatch: "",
                    supportAttr: "",
                    userId: "",
                },
                orderFinanceDetail: {
                    changeTime: "",
                    createTime: "",
                    discountAmount: "",
                    discountRate: "",
                    entryPriceInfo: "",
                    id: "",

                    materialCode: "",
                    materialId: "",
                    materialName: "",
                    netPrice: "",
                    orderId: "",
                    priceCeiling: "",
                    priceCoefficient: "",
                    priceFloor: "",
                    pricingNum: "",
                    pricingUnit: "",
                    settlementDept: "",
                    systemPricing: "",
                    taxRate: "",
                    unitPriceDiscount: "",
                    userId: "",
                },
                orderOther: {
                    businessClose: "",
                    businessFreeze: "",
                    businessProcess: "",
                    businessStop: "",
                    changeTime: "",
                    contractsCode: "",
                    createTime: "",
                    freezeName: "",
                    freezeTime: "",
                    id: "",
                    inventoryReturnNum: "",
                    isPlanConfirm: "",
                    isQuotaGeneration: "",

                    materialCode: "",
                    materialId: "",
                    materialName: "",
                    materialReceivedReturnNum: "",
                    orderId: "",
                    planTrackingCode: "",
                    requireDocCode: "",
                    requireDocLineCode: "",
                    requireFrom: "",
                    requireTrackingCode: "",
                    sourceDocCode: "",
                    sourceDocType: "",
                    stopName: "",
                    stopTime: "",
                    surplusInboundNum: "",
                    surplusMaterialReceivedNum: "",
                    totalInboundNum: "",
                    totalMaterialReceivedNum: "",
                    totalMaterialReturnNum: "",
                    updateFlag: "",
                    userId: "",
                },
                originalContainsTaxPrice: "",
                originalNumber: "",
                page: 0,
                parentMaterial: "",
                price: "",
                pricingNum: "",
                pricingUnit: "",
                pricingUnitName: "",
                purchaseUnit: "",
                purchaseUnitName: "",
                ramarks: "",
                receivedFirstTicketsNum: "",
                receivingDept: "",
                receivingDeptName: "",
                relationId: "",
                requireDept: "",
                requireDeptName: "",
                settlementDept: "",
                settlementDeptName: "",
                sourceDocCode: "",
                sourceDocType: "",
                sourceRelationId: "",
                supplierMaterialCode: "",
                supplierMaterialName: "",
                taxAmount: "",
                taxMoney: "",
                taxPrice: "",
                taxRate: "",
                token: "",
                totalAcceptanceAmount: "",
                totalAcceptanceRate: "",
                totalTaxPrice: "",
                type: 0,
                warehouseId: "",
                warehouseRegionId: "",
                directRate: "",
                indirectRate: "",
            };
            // 税率
            getTaxData().then((res) => {
                obj.taxRate = res.rows[0].rate;
            });
            // 结算组织
            getInfo().then((res) => {
                obj.settlementDept = res.deptId;
                obj.settlementDeptName = res.deptName;
            });
            return obj;
        },
        getSummaries(param) {
            const { columns, data } = param;
            const sums = [];
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = "总计";
                    return;
                }
                if (
                    column.property === "number" ||
                    column.property === "pricingNum" ||
                    column.property === "amountMoney" ||
                    column.property === "totalTaxPrice"
                ) {
                    const values = data.map((item) =>
                        Number(item[column.property])
                    );
                    if (!values.every((value) => isNaN(value))) {
                        sums[index] = values.reduce((prev, curr) => {
                            const value = Number(curr);
                            if (!isNaN(value)) {
                                return prev + curr;
                            } else {
                                return prev;
                            }
                        }, 0);
                        sums[index] += "";
                    } else {
                        sums[index] = "N/A";
                    }
                } else {
                    return;
                }
            });

            return sums;
        },
        // 初始化默认数据
        initDefaultData() {
            // 结算币别
            getCurrencyData().then((res) => {
                this.formObject.contractSaleEntity.settlementCurrencyId =
                    res.rows[0].id;
                this.formObject.contractSaleEntity.settlementCurrencyName =
                    res.rows[0].currencyName;
                this.formObject.contractSaleEntity.settlementCurrencyCode =
                    res.rows[0].code;
                // 本位币
                this.formObject.contractSaleEntity.standardCurrency =
                    res.rows[0].id;
                this.formObject.contractSaleEntity.standardCurrencyName =
                    res.rows[0].currencyName;
                this.formObject.contractSaleEntity.standardCurrencyCode =
                    res.rows[0].code;
                this.formObject.contractSaleEntity.rate = res.rows[0].rate;
            });
            // 收款条件
            getPayData({ type: 1 }).then((res) => {
                this.formObject.contractSaleEntity.receiptTermsId =
                    res.rows[0].id;
                this.formObject.contractSaleEntity.receiptTermsName =
                    res.rows[0].title;
            });
            // 汇率类型
            getExchangeTypeData().then((res) => {
                this.formObject.contractSaleEntity.rateType = res.rows[0].id;
                this.formObject.contractSaleEntity.rateTypeName =
                    res.rows[0].name;
            });
            // 销售组织
            getInfo().then((res) => {
                this.formObject.contractSaleEntity.saleDeptId = res.deptId;
                this.formObject.contractSaleEntity.saleDeptName = res.deptName;
            });
        },
    },
    created() {
        this.initDefaultData();
        if (this.id) {
            this.getDetailData(this.id);
        }
    },
};
</script>
<style lang="scss" scoped>
::v-deep .el-table td.el-table__cell div {
    overflow: visible;
}

::v-deep .el-table td.el-table__cell {
    padding-bottom: 20px;
}
</style>
